package com.dq.vo;

import com.dq.vo.baseVo.VO;;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.http.HttpStatus;


/**
 * 返回给app
 */
@Data
@ApiModel(value = "返回封装")
public class Vo <T extends Object> implements VO {
    @ApiModelProperty(value = "状态码")
    private String code; // 状态码, "200"为正常, 其余为错误
    @ApiModelProperty(value = "提示信息")
    private String message; // 提示信息
    @ApiModelProperty(value = "数据内容")
    private T data; // 数据

    public Vo() {
    }

    public Vo(HttpStatus status) {
        this.message = status.getReasonPhrase();
        this.code = status.toString();
    }

    public Vo(HttpStatus status, String message) {
        this.message = message != null ? message : status.getReasonPhrase();
        this.code = status.toString();
    }

    public Vo(T data) {
        this.message = HttpStatus.OK.getReasonPhrase();
        this.code = HttpStatus.OK.toString();
        this.data = data;
    }

    public Vo(String code, String message, T data) {
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public Vo(String code, String message) {
        this.message = message;
        this.code = code;
    }
}
